# eric7.MicroPython.MicroPythonFileManager

Module implementing some file system commands for MicroPython.

### Global Attributes

None

### Classes

MicroPythonFileManager | Class implementing an interface to the device file system commands with some additional sugar.

### Functions

None

## MicroPythonFileManager

Class implementing an interface to the device file system commands with some additional sugar.

### Signals

createDirectoryDone()
  emitted after a directory was created
currentDir(dirname)
  emitted to report the current directory of the device
currentDirChanged(dirname)
  emitted to report back a change of the current directory
deleteFileDone(deviceFile)
  emitted after the file has been deleted on the connected device
error(exc)
  emitted with a failure message to indicate a failure during the most recent operation
fsinfoDone(fsinfo)
  emitted after the file system information was obtained
getFileDone(deviceFile, localFile)
  emitted after the file was fetched from the connected device and written to the local file system
hashDone(deviceFile, hash)
  emitted after the hash has been calculated for the file on the connected device
longListFiles(result)
  emitted with a tuple of tuples containing the name, mode, size and time for each directory entry
putDataDone(deviceFile)
  emitted after data has been save to a file on the connected device
putFileDone(localFile, deviceFile)
  emitted after the file was copied to the connected device
removeDirectoryDone()
  emitted after a directory has been deleted
rsyncDone(localName, deviceName)
  emitted after the rsync operation has been completed
rsyncProgressMessage(msg)
  emitted to send a message about what rsync is doing
touchFileDone(deviceFile)
  emitted after the file has been touched on the connected device

### Derived from

QObject

### Class Attributes

None

### Class Methods

None

### Methods

MicroPythonFileManager | Constructor
__rsync | Private method to synchronize a local directory to the device.
cd | Public slot to change the current directory of the device.
delete | Public slot to delete a file on the device.
exists | Public method to check the existence of a file or directory.
fileSystemInfo | Public method to obtain information about the currently mounted file systems.
get | Public slot to get a file from the connected device.
getData | Public method to read data from the connected device.
hashFile | Public method to generate a hash of a file on the connected device.
lls | Public slot to get a long listing of the given directory.
makedirs | Public slot to create a new directory and all intermediates.
mkdir | Public slot to create a new directory.
put | Public slot to put a file onto the device.
putData | Public method to write data to the connected device.
pwd | Public slot to get the current directory of the device.
rename | Public method to rename a file on the device.
rmdir | Public slot to (recursively) remove a directory.
rsync | Public slot to synchronize a local directory to the device.
touchFile | Public method to touch a file on the connected device.
writeFile | Public method to write some text to a file on the connected device.

### Static Methods

None

#### MicroPythonFileManager (Constructor)

MicroPythonFileManager(device, parent=None)

Constructor

device (BaseDevice)
  MicroPython device object
parent (QObject)
  reference to the parent object

#### MicroPythonFileManager.__rsync

__rsync(hostDirectory, deviceDirectory, mirror=True, localDevice=False, indentLevel=0, )

Private method to synchronize a local directory to the device.

hostDirectory (str)
  name of the local directory
deviceDirectory (str)
  name of the directory on the device
mirror (bool)
  flag indicating to mirror the local directory to the device directory
localDevice (bool)
  flag indicating device access via local file system
indentLevel (int)
  indentation level for progress messages

Return:
  list of errors

Return Type:
  list of str

#### MicroPythonFileManager.cd

cd(dirname)

Public slot to change the current directory of the device.

dirname (str)
  name of the desired current directory

#### MicroPythonFileManager.delete

delete(deviceFileName)

Public slot to delete a file on the device.

deviceFileName (str)
  name of the file on the connected device

#### MicroPythonFileManager.exists

exists(pathname)

Public method to check the existence of a file or directory.

pathname (str)
  name of the path to check

Return:
  flag indicating the existence

Return Type:
  bool

#### MicroPythonFileManager.fileSystemInfo

fileSystemInfo()

Public method to obtain information about the currently mounted file systems.

#### MicroPythonFileManager.get

get(deviceFileName, hostFileName="")

Public slot to get a file from the connected device.

deviceFileName (str)
  name of the file on the device
hostFileName (str)
  name of the local file

#### MicroPythonFileManager.getData

getData(deviceFileName)

Public method to read data from the connected device.

deviceFileName (str)
  name of the file to read from

Return:
  data read from the device

Return Type:
  bytes

#### MicroPythonFileManager.hashFile

hashFile(deviceFileName, algorithm="sha256", chunkSize=256)

Public method to generate a hash of a file on the connected device.

deviceFileName (str)
  name of the file on the connected device
algorithm (str (optional))
  hashing algorithm to be used (defaults to "sha256")
chunkSize (int (optional))
  size of data chunks to be sent to the algorithm (defaults to 256)

#### MicroPythonFileManager.lls

lls(dirname, showHidden=False)

Public slot to get a long listing of the given directory.

dirname (str)
  name of the directory to list
showHidden (bool)
  flag indicating to show hidden files as well

#### MicroPythonFileManager.makedirs

makedirs(dirname)

Public slot to create a new directory and all intermediates.

dirname (str)
  name of the directory to create

#### MicroPythonFileManager.mkdir

mkdir(dirname)

Public slot to create a new directory.

dirname (str)
  name of the directory to create

#### MicroPythonFileManager.put

put(hostFileName, deviceFileName="")

Public slot to put a file onto the device.

hostFileName (str)
  name of the local file
deviceFileName (str)
  name of the file on the connected device

#### MicroPythonFileManager.putData

putData(deviceFileName, data)

Public method to write data to the connected device.

deviceFileName (str)
  name of the file to write to
data (bytes)
  data to write

#### MicroPythonFileManager.pwd

pwd()

Public slot to get the current directory of the device.

#### MicroPythonFileManager.rename

rename(oldname, newname)

Public method to rename a file on the device.

oldname (str)
  current name of the file
newname (str)
  new name for the file

Return:
  flag indicating success

Return Type:
  bool

#### MicroPythonFileManager.rmdir

rmdir(dirname, recursive=False)

Public slot to (recursively) remove a directory.

dirname (str)
  name of the directory to be removed
recursive (bool)
  flag indicating a recursive removal

#### MicroPythonFileManager.rsync

rsync(hostDirectory, deviceDirectory, mirror=True, localDevice=False)

Public slot to synchronize a local directory to the device.

hostDirectory (str)
  name of the local directory
deviceDirectory (str)
  name of the directory on the device
mirror (bool)
  flag indicating to mirror the local directory to the device directory
localDevice (bool)
  flag indicating device access via local file system

#### MicroPythonFileManager.touchFile

touchFile(deviceFileName)

Public method to touch a file on the connected device.

deviceFileName (str)
  name of the file on the connected device

#### MicroPythonFileManager.writeFile

writeFile(filename, text)

Public method to write some text to a file on the connected device.

filename (str)
  name of the file on the connected device
text (str)
  text to be written

Return:
  flag indicating success

Return Type:
  bool

Up